#pragma once
#include <algorithm>
#include <iostream>
#include <random>
#include <set>

using namespace std;

class RandomTest
{
public:
	void Init(std::function<int()> g, int count, int width)
	{
		this->g = g;
		this->count = count;
		this->width = width;
	}

	void TestRandomness()
	{
		set<int> check;
		int repeat = 0;
		for (int i = 0; i < count; ++i)
		{
			int r = g();
			if (check.find(r) != check.end())
			{
				repeat++;
			}
			else
			{
				check.insert(r);
			}
		}
		cout << "repeat " << repeat << " count" << endl;
	}


	void TestDistribution()
	{
		int idx = 0;
		int* weight = new int[width];
		for (int i = 0; i < width; ++i)
		{
			weight[i] = 0;
		}
		for (int i = 0; i < 1000000; ++i)
		{
			idx = g() % width;
			weight[idx]++;
		}

		for (int i = 0; i < width; ++i)
		{
			cout << 1.0 * weight[i] / count << ", ";
		}
		cout << endl;
	}

	void TestPerformance()
	{
		for (int i = 0; i < count; ++i)
		{
			g();
		}
	}

private:
	function<int()> g;
	int count;
	int width;
};